#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100;

int f[6][6][6][6][6],s,n,to[1010],c[6],k[6];
int need[6],p[6];

typedef struct {int tot,c[6],k[6],p,ff[6];} favorate;

favorate fav[10];

int main (){
	scanf("%d",&s);
	for(int i = 1;i <= s;i++){
		scanf("%d",&fav[i].tot);
		for(int j = 0;j < fav[i].tot;j++){
			scanf("%d %d",&fav[i].c[j],&fav[i].k[j]);
		}
		scanf("%d",&fav[i].p);
	}
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d %d %d",&c[i],&k[i],&p[i]);
		to[c[i]] = i;
	}
	for(int i = 1;i <= s;i++){
		for(int j = 0;j < fav[i].tot;j++){
			fav[i].ff[to[fav[i].c[j]]] = fav[i].k[j];
		}
	}
	for(int k1 = 0;k1 <= k[1];k1++)
		for(int k2 = 0;k2 <= k[2];k2++)
			for(int k3 = 0;k3 <= k[3];k3++)
				for(int k4 = 0;k4 <= k[4];k4++)
					for(int k5 = 0;k5 <= k[5];k5++)
						f[k1][k2][k3][k4][k5] = k1 *p[1] + k2 * p[2] + k3 * p[3] + k4 * p[4] + k5 * p[5];
	for(int i = 1;i <= s;i++)
		for(int k1 = fav[i].ff[1];k1 <= k[1];k1++)
			for(int k2 = fav[i].ff[2];k2 <= k[2];k2++)
				for(int k3 = fav[i].ff[3];k3 <= k[3];k3++)
					for(int k4 = fav[i].ff[4];k4 <= k[4];k4++)
						for(int k5 = fav[i].ff[5];k5 <= k[5];k5++)
							f[k1][k2][k3][k4][k5] = min(f[k1][k2][k3][k4][k5],f[k1-fav[i].ff[1]][k2-fav[i].ff[2]][k3-fav[i].ff[3]][k4-fav[i].ff[4]][k5-fav[i].ff[5]] + fav[i].p);
	printf("%d\n",f[k[1]][k[2]][k[3]][k[4]][k[5]]);
	return 0;
}
